package com.nageoffer.jobtrain.projects.common.config;

import com.nageoffer.jobtrain.projects.common.biz.user.PreventSmsSkimFilter;
import com.nageoffer.jobtrain.projects.common.biz.user.UserTransmitFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 用户设置过滤器
 * author：唐晨
 */
@Configuration
@RequiredArgsConstructor
public class UserFilterConfiguration {
    private final StringRedisTemplate stringRedisTemplate;

    /**
     * 用户信息传递过滤器配置
     */
    @Bean
    public FilterRegistrationBean<PreventSmsSkimFilter> globalPreventSmsSkimFilter() {
        FilterRegistrationBean<PreventSmsSkimFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new PreventSmsSkimFilter(stringRedisTemplate));
        registration.addUrlPatterns("/*");
        // 设置过滤器的优先级
        registration.setOrder(1);
        return registration;
    }

    /**
     * 用户上下文信息过滤器配置
     */
    @Bean
    public FilterRegistrationBean<UserTransmitFilter> UserTransmitFilter() {
        FilterRegistrationBean<UserTransmitFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new UserTransmitFilter());
        registration.addUrlPatterns("/*");
        // 设置过滤器的优先级
        registration.setOrder(10);
        return registration;
    }
}